package com.itheima.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
重定向
 */
@WebServlet("/responseServlet01")
public class ResponseServlet01 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("responseServlet01被访问了");

       /* //设置响应状态码
        response.setStatus(302);
        //设置响应头
        response.setHeader("location","/responseServlet02");*/

       /*//简单的重定向
            //动态获取虚拟路径
        String contextPath = request.getContextPath();
        response.sendRedirect(contextPath+"/responseServlet02");*/

        //重定向可以访问任意网站资源
        response.sendRedirect("http://www.baidu.com");

        request.setAttribute("msg","response");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
